﻿/*
*  封装的对象模型
*/
//同步加载
function GetSmJSON(URL, PARAM, SUCCESSFUN) {
	var xht=null;
    $.ajax({
        async: false,
        url: URL,
        type: "POST",
        //dataType: "json",
        xhr:function(){
    	
        },
        data:PARAM,// $.param(PARAM),
        contentType: "application/x-www-form-urlencoded; charset=utf-8",//"application/json; charset=utf-8",
        success: function (json) {
    	 var json=parseResponseText(XMLHttpRequest.responseText);
            SUCCESSFUN(json);
        },
          error: function(XMLHttpRequest, textStatus, errorThrown) {  //#3这个error函数调试时非常有用，如果解析不正确，将会弹出错误框
                        alert(XMLHttpRequest.status);
//                        alert(XMLHttpRequest.readyState);
//                        alert(textStatus); // paser error;
                    }
    });
};
function GetSmJSON2(url,para,SUCCESSFUN)
{
xmlhttp=null;
if (window.XMLHttpRequest)
  {// code for IE7, Firefox, Opera, etc.
  xmlhttp=new XMLHttpRequest();
  }
else if (window.ActiveXObject)
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
if (xmlhttp!=null)
  {
  xmlhttp.onreadystatechange=SUCCESSFUN;
  xmlhttp.open("POST",url,false);
  xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
  xmlhttp.send(para);
  }
else
  {
  alert("Your browser does not support XMLHTTP.");
  }
}

function callback()
{
if (xmlhttp.readyState==4)
  {// 4 = "loaded"
  if (xmlhttp.status==200)
    {// 200 = "OK"
   
    alert(parseResponseText(xmlhttp.responseText));
    }
  else
    {
    alert("Problem retrieving XML data:" + xmlhttp.statusText);
    }
  }
}
//解析获取后台返回的数据
function parseResponseText(respTxt){
	if(respTxt!=""){
		if(respTxt.charAt(0)==='<'){
			var g=respTxt.indexOf(':');
			if(g>-1){
				var h=respTxt.substring(1,g);
				var startstr="<"+h+":return>";
				var start=respTxt.indexOf(startstr);
				var end=respTxt.indexOf("</"+h+":return>");
				if(start>-1&&end>-1){
					respTxt=respTxt.substring(start+startstr.length,end);
				}
			}
		}
	}
	return respTxt;
}
//异步加载
function GetSmJSONAsync(URL, PARAM, SUCCESSFUN, succallback) {
    $.ajax({
        async: true,
        url: URL,
        type: "POST",
       // dataType: "json",
        data: PARAM,
        contentType: "application/json; charset=utf-8",
        success: function (json) {
            SUCCESSFUN(json.d);
            succallback(json.d);
        },
        error: function (x, e) {
        }
    });
};

//哈希表
function SmHashtable() {
    this.Data = undefined;
    this.Init = function (url, param) {
        var sf = this;
        GetSmJSON(url, param, function (txt) {
            sf.Data = JSON.parse(txt);
        });
    };
    this.GetValue = function (field) {
        var sf = this;
        for (var i in sf.Data) {
            if (sf.Data[i].Key == field) return sf.Data[i].Value;
        }
        return "";
    };
};

//SmObjectData对象模型
function SmObjectData(tablename) {
    this.ID = "";
    this.Key = "";
    this.TableName = tablename;
    this.DBAlias = "s4108";
    this.Data = undefined;
    this.Init = function (key, id, fields) {
        var sf = this;
        sf.Key = key;
        sf.ID = id;
        if (fields == "" || fields == undefined || fields == null) fields = "*";
        var url = CLDJServiceUrl + "/smData/GetSmObjectData";
        //var param = "{'tablename':'" + this.TableName + "','key':'" + this.Key + "','keyvalue':'" + this.ID + "','fields':'" + fields + "'}";
         var param = "tablename=" + this.TableName + "&key=" + this.Key + "&keyvalue=" + this.ID + "&fields=" + fields ;
        GetSmJSON2(url, param, function () {
        	 if (xmlhttp.readyState==4)
             {// 4 = "loaded"
                if (xmlhttp.status==200)
                 {// 200 = "OK"
                    var txt= parseResponseText(xmlhttp.responseText);
            sf.Data = JSON.parse(txt);
       }
       }
        });
    };
    this.GetFirstSmObject = function (condition, fields) {
        var sf = this;
        if (fields == "" || fields == undefined || fields == null) fields = "*";
        var url = CLDJServiceUrl + "/smData/GetFirstSmObject";
        var param = "tablename=" + sf.TableName + "&condition=" + condition + "&fields=" + fields;
        GetSmJSON2(url, param, function () {
            	 if (xmlhttp.readyState==4)
             {// 4 = "loaded"
                if (xmlhttp.status==200)
                 {// 200 = "OK"
                    var txt= parseResponseText(xmlhttp.responseText);
            sf.Data = JSON.parse(txt);
       }
       }
        });
    };
    this.GetValue = function (field) {
//        for (var i in this.Data.m_data) {
//            if (this.Data.m_data[i].Key == field) {
//                var v = this.Data.m_data[i].Value;
//                var patt1 = new RegExp("<BR>", "g");
//                if (patt1.test(v)) {
//                    return v.replace(patt1, "\r\n");
//                } else return v;
//
//            }
//        }
    	var v="";
    		v=eval( "this.Data.m_data."+field);
        return v;
    };
    this.SetValue = function (field, value) {
//        for (var i in this.Data.m_data) {
//            if (this.Data.m_data[i].Key == field) {
//                this.Data.m_data[i].Value = value;
//                return true;
//            }
//        }
    	eval( "this.Data.m_data."+field+"='"+value+"'");
        return true;
    };
    this.Save = function (service, param1) {//'a':'v','b':'v'
        var param = "json=" + JSON.stringify(this.Data);
//        if (param1 != undefined) {
//            param = "{'json':'" + JSON.stringify(this.Data) + "'," + param1 + "}";
//        }
        var res = false;
        GetSmJSON2(service, param, function () {
        	   	 if (xmlhttp.readyState==4)
             {// 4 = "loaded"
                if (xmlhttp.status==200)
                 {// 200 = "OK"
                    var txt= parseResponseText(xmlhttp.responseText);
            res = txt;
       }
       }
        });
        return res;
    };
    //通用的方法，把表和数据库别名加进去，后台统一保存，不用每个都写自己的服务
    this.Update = function () {
        var param = "json=" + JSON.stringify(this.Data) ;
        var res = false;
        service = CLDJServiceUrl + "/smData/UpdateSmObject";
        GetSmJSON2(service, param, function () {
              	 if (xmlhttp.readyState==4)
             {// 4 = "loaded"
                if (xmlhttp.status==200)
                 {// 200 = "OK"
                    var txt= parseResponseText(xmlhttp.responseText);
            res = txt;
            }
                }
        });
        return res;
    };
    this.UpdateObj = function () {
        var param = "{'json':'" + JSON.stringify(this.Data) + "'}";
        var res = false;
        service = CLDJServiceUrl + "/smData/UpdateSmObj";
        GetSmJSON(service, param, function (txt) {
            res = txt;
        });
        return res;
    };
    this.Delete = function () {
        var param = "{'json':'" + JSON.stringify(this.Data) + "'}";
        var res = false;
        service = CLDJServiceUrl + "/smData/DeleteSmObject";
        GetSmJSON(service, param, function (txt) {
            res = txt;
        });
        return res;
    };

    this.DeleteEx = function () {
        var param = "{'json':'" + JSON.stringify(this.Data) + "'}";
        var res = false;
        service = CLDJServiceUrl + "/smData/DeleteSmObjectEx";
        GetSmJSON(service, param, function (txt) {
            res = txt;
        });
        return res;
    };
};

//SmPageData对象模型
function SmPageData(tablename, pagesize) {
    this.DBAlias = "s4108";
    this.TableName = tablename;
    this.Key = "";
    this.Fields = "*";
    this.Data = undefined;
    this.PageSize = pagesize || 5;
    this.PageIndex = 1;
    this.Filter = "";
    this.SelectedID = 0;
    this.PageCount = 1;
    this.RecordCount = 1;
    this.ColumnCount = 1;
    this.PageRecordCount = 1;
    this.OrderBy = "";
    this.OrderByType = 0;
    this.InitEx = function () {
        this.Init(this.Key, this.Fields, this.Filter,this.OrderBy,this.OrderByType);
    }
    //主键key,字段*,条件""
    this.Init = function (key, fields, filter, orderby, orderbytype) {
        var sf = this;
        sf.Key = key;
        sf.Fields = fields;
        sf.Filter = filter;
        if (orderby == undefined) {
            sf.OrderBy = key;
        }
        else {
            sf.OrderBy = orderby;
        }
        if (orderbytype == undefined) {
            sf.OrderByType = 0;
        }
        else {
            sf.OrderByType = orderbytype;
        }
        var url = CLDJServiceUrl + "/smData/GetSmPageData";
        var param1 = "";
        param1 += "tablename=" + sf.TableName + "&";
        param1 += "key=" + sf.Key + "&";
        param1 += "selectfield=" + sf.Fields + "&";
        param1 += "filter=" + sf.Filter + "&";
        param1 += "orderby=" + sf.OrderBy + "&";
        param1 += "orderbytype=" + sf.OrderByType + "&";
        param1 += "pagesize=" + sf.PageSize + "&";
        param1 += "pageindex=" + sf.PageIndex 
        param1 += "";
        GetSmJSON2(url, param1, function () {
        	 if (xmlhttp.readyState==4)
             {// 4 = "loaded"
                if (xmlhttp.status==200)
                 {// 200 = "OK"
                    var txt= parseResponseText(xmlhttp.responseText);
            sf.Data = JSON.parse(txt);
            if (sf.Data != undefined) {
                sf.PageCount = sf.Data.m_PageCount;
                sf.RecordCount = sf.Data.m_RecordCount;
                sf.ColumnCount = sf.Data.m_ColumnCount;
                sf.PageRecordCount = sf.Data.m_PageRecordCount;
            }
            }
                }
        });
    };
    this.Refresh = function () {
        var sf = this;
        var url = CLDJServiceUrl + "/smData/GetSmPageData";
        var param1 = "";
        param1 += "tablename=" + sf.TableName + "&";
        param1 += "key=" + sf.Key + "&";
        param1 += "selectfield=" + sf.Fields + "&";
        param1 += "filter=" + sf.Filter + "&";
        param1 += "orderby=" + sf.OrderBy + "&";
        param1 += "orderbytype=" + sf.OrderByType + "&";
        param1 += "pagesize=" + sf.PageSize + "&";
        param1 += "pageindex=" + sf.PageIndex
        param1 += "";
        GetSmJSON2(url, param1, function () {
        	 if (xmlhttp.readyState==4)
             {// 4 = "loaded"
                if (xmlhttp.status==200)
                 {// 200 = "OK"
                    var txt= parseResponseText(xmlhttp.responseText);
            sf.Data = JSON.parse(txt);
            if (sf.Data != undefined) {
                sf.PageCount = sf.Data.m_PageCount;
                sf.RecordCount = sf.Data.m_RecordCount;
                sf.ColumnCount = sf.Data.m_ColumnCount;
                sf.PageRecordCount = sf.Data.m_PageRecordCount;
            }
            }
                }
        });
    };
    this.PageDown = function () {
        if (this.Data != undefined) {
            this.PageIndex++;
            if (this.PageIndex > this.Data.PageCount) {
                this.PageIndex = this.Data.PageCount;
            }
            this.InitEx();
        }
    };
    this.PageUp = function () {
        if (this.Data != undefined) {
            this.PageIndex--;
            if (this.PageIndex < 1) {
                this.PageIndex = 1;
            }
            this.InitEx();
        }
    };
    this.First = function () {
        if (this.Data != undefined) {
            this.PageIndex = 1;
            this.InitEx();
        }
    };
    this.Last = function () {
        if (this.Data != undefined) {
            this.PageIndex = this.Data.PageCount;
            this.InitEx();
        }
    };

    this.Select = function (id) {
        this.SelectedID = id;
        if (typeof this.OnSelect == "function") {
            this.OnSelect();
        }
    };
    this.GetSelectedSmObject = function () {
        var obj = new SmObjectData(this.DBAlias, this.TableName);
        obj.Init(this.Key, this.SelectedID);
        return obj;
    };

    this.GetKeyIndex = function (key) {
        var self = this;
        if (self.Data != undefined && self.ColumnCount > 0) {
            for (var i = 0; i < self.ColumnCount; i++) {
                if (self.Data.m_strCaptions[i] == key) return i;
            }
        }
        return -1;
    };

    this.GetEasyuiGridData = function () {
        var self = this;
        if (self.Data != undefined && self.ColumnCount > 0 && self.RecordCount > 0) {
            var grid = "{";
            grid += "\"total\":" + self.PageRecordCount + ",";
            grid += "\"rows\":["
            for (var r = 0; r < self.PageRecordCount; r++) {
                grid += "{"
                for (var i = 0; i < self.ColumnCount; i++) {
                    if (i == self.ColumnCount - 1) {
                        grid += "\"" + self.Data.m_strCaptions[i] + "\":\"" + self.Data.m_rows[r][i] + "\"";
                    } else {
                        grid += "\"" + self.Data.m_strCaptions[i] + "\":\"" + self.Data.m_rows[r][i] + "\",";
                    }
                }
                if (r == self.PageRecordCount - 1) {
                    grid += "}"
                } else {
                    grid += "},"
                }
            }
            grid += "]}"
            return JSON.parse(grid);
        } else {
            return JSON.parse("{ \"total\": 0, \"rows\": [] }");
        }
        return null;
    }
};


//适合小数据量查询
function SmDataTable() {
    this.DBAlias = "s4108";
    this.Data = undefined;
    this.RecordCount = 0;
    this.ColumnCount = 0;
    this.Flag = "";
    this.FlagEx = "";
    this.Init = function (sql) {
        var sf = this;
        var url = CLDJServiceUrl + "/smData/GetSmDataTable";
        var param1 = "";
        param1 += "sql=" + sql ;
        //param1 += "}";
        GetSmJSON2(url, param1, function () {
            if (xmlhttp.readyState==4)
             {// 4 = "loaded"
                if (xmlhttp.status==200)
                 {// 200 = "OK"
                    var txt= parseResponseText(xmlhttp.responseText)
                  sf.Data = JSON.parse(txt);
            
            if (sf.Data != undefined) {
                sf.RecordCount = sf.Data.m_Rows.length;
                sf.ColumnCount = sf.Data.m_Captions.length;
//                sf.Flag = sf.Data.Flag;
//                sf.FlagEx = sf.Data.FlagEx;
            }
            }
                }
        });
    };
    
    this.GetKeyIndex = function (key) {
        var self = this;
        if (self.Data != undefined && self.ColumnCount > 0) {
            for (var i = 0; i < self.ColumnCount; i++) {
                if (self.Data.m_strCaptions[i] == key) return i;
            }
        }
        return -1;
    };

    this.GetEasyuiGridData = function () {
        var self = this;
        if (self.Data != undefined && self.ColumnCount > 0 && self.RecordCount > 0) {
            var grid = "{";
            grid += "\"total\":" + self.RecordCount + ",";
            grid += "\"rows\":["
            for (var r = 0; r < self.RecordCount; r++) {
                grid += "{"
                for (var i = 0; i < self.ColumnCount; i++) {
                    if (i == self.ColumnCount - 1) {
                        grid += "\"" + self.Data.m_Captions[i] + "\":\"" + self.Data.m_Rows[r][i] + "\"";
                    } else {
                        grid += "\"" + self.Data.m_Captions[i] + "\":\"" + self.Data.m_Rows[r][i] + "\",";
                    }
                }
                if (r == self.RecordCount - 1) {
                    grid += "}"
                } else {
                    grid += "},"
                }
            }
            grid += "]}"
            return JSON.parse(grid);
        } else {
            return JSON.parse("{ \"total\": 0, \"rows\": [] }");
        }
        return null;
    };

    this.GetEasyuiComboBoxData = function () {
        var self = this;
        if (self.Data != undefined && self.ColumnCount > 0 && self.RecordCount > 0) {
            var grid = "[";
            if (self.RecordCount == 0) {
                grid += "{\"id\":\"\",\"text\":\"请选择\"}";
            }
            else {
                grid += "{\"id\":\"\",\"text\":\"请选择\"},";
            }
            for (var r = 0; r < self.RecordCount; r++) {
                grid += "{"
                grid += "\"id\":\"" + self.Data.m_Rows[r][0] + "\",";
                grid += "\"text\":\"" + self.Data.m_Rows[r][1] + "\"";
                if (r == self.RecordCount - 1) {
                    grid += "}"
                } else {
                    grid += "},"
                }
            }
            grid += "]"
            return JSON.parse(grid);
            //return grid;
        }
        return null;
    }

};
//词表
function SmCB() {
    this.Data = undefined;
    this.InitCB01 = function (dm) {
        var sf = this;
        var url = CLDJServiceUrl + "/SmwsFrame.asmx/GetGT_CB01";
        var param1 = "{";
        param1 += "'dm':'" + dm + "'";
        param1 += "}";
        GetSmJSON(url, param1, function (txt) {
            sf.Data = JSON.parse(txt);
        });
        return sf.Data;
    }
    this.InitCB02 = function (dm) {
        var sf = this;
        var url = CLDJServiceUrl + "/SmwsFrame.asmx/GetGT_CB02";
        var param1 = "{";
        param1 += "'dm':'" + dm + "'";
        param1 += "}";
        GetSmJSON(url, param1, function (txt) {
            sf.Data = JSON.parse(txt);
        });
        return sf.Data;
    }
    this.InitCB03 = function (dm) {
        var sf = this;
        var url = CLDJServiceUrl + "/SmwsFrame.asmx/GetGT_CB03";
        var param1 = "{";
        param1 += "'dm':'" + dm + "'";
        param1 += "}";
        GetSmJSON(url, param1, function (txt) {
            sf.Data = JSON.parse(txt);
        });
        return sf.Data;
    }
    this.InitCB05 = function () {
        var sf = this;
        var url = CLDJServiceUrl + "/SmwsFrame.asmx/GetGT_CB05";
        var param1 = "{";
        param1 += "}";
        GetSmJSON(url, param1, function (txt) {
            sf.Data = JSON.parse(txt);
        });
        return sf.Data;
    }
    this.GetXZQTree = function (xzqdm) {
        var sf = this;
        var url = CLDJServiceUrl + "/SmwsFrame.asmx/GetXZQTree";
        var param1 = "{";
        param1 += "'xzqdm':'" + xzqdm + "'";
        param1 += "}";
        GetSmJSON(url, param1, function (txt) {
            sf.Data = JSON.parse(txt);
        });
        return sf.Data;
    }
    this.GetXZQTreeEx = function (xzqdm) {
        var sf = this;
        var url = CLDJServiceUrl + "/SmwsFrame.asmx/GetXZQTreeEx";
        var param1 = "{";
        param1 += "'xzqdm':'" + xzqdm + "'";
        param1 += "}";
        GetSmJSON(url, param1, function (txt) {
            sf.Data = JSON.parse(txt);
        });
        return sf.Data;
    }
    this.GetKCDMTree = function () {
        var sf = this;
        var url = CLDJServiceUrl + "/SmwsFrame.asmx/GetKCDMTree";
        var param1 = "{";
        param1 += "}";
        GetSmJSON(url, param1, function (txt) {
            sf.Data = JSON.parse(txt);
        });
        return sf.Data;
    }
    this.InitCB09 = function () {
        var sf = this;
        var url = CLDJServiceUrl + "/SmwsFrame.asmx/GetGT_CB09";
        var param1 = "{";
        param1 += "}";
        GetSmJSON(url, param1, function (txt) {
            sf.Data = JSON.parse(txt);
        });
        return sf.Data;
    }
    this.InitCB12 = function (dm) {
        var sf = this;
        var url = CLDJServiceUrl + "/SmwsFrame.asmx/GetGT_CB12";
        var param1 = "{";
        param1 += "'dm':'" + dm + "'";
        param1 += "}";
        GetSmJSON(url, param1, function (txt) {
            sf.Data = JSON.parse(txt);
        });
        return sf.Data;
    }
    this.InitCB13 = function () {
        var sf = this;
        var url = CLDJServiceUrl + "/SmwsFrame.asmx/GetGT_CB13";
        var param1 = "{";
        param1 += "}";
        GetSmJSON(url, param1, function (txt) {
            sf.Data = JSON.parse(txt);
        });
        return sf.Data;
    }
    this.InitCB16 = function () {
        var sf = this;
        var url = CLDJServiceUrl + "/SmwsFrame.asmx/GetGT_CB16";
        var param1 = "{";
        param1 += "}";
        GetSmJSON(url, param1, function (txt) {
            sf.Data = JSON.parse(txt);
        });
        return sf.Data;
    }
}

//用户登录
function SmUser() {
    this.USER_ID = ""; //用户ID
    this.LOGIN_NAME = ""; //用户代码
    this.NAME = ""; //用户名
    this.IndexPage = "index.html";
    this.HomePage = "frame.html";
    this.Pass = false; //是否登录成功
    this.LERVER = "";
    this.XZQDM = "";
    this.Role_Name = "";
    this.Msg = "";
    this.DEPT_ID = "";

    //获取当前浏览器用户登录状态
    this.GetCurrentUser = function () {
        var sf = this;
        var url = CLDJServiceUrl + "/SmwsFrame/GetCurrentUser";
        var param = "";
        GetSmJSON2(url, param, function () {
        	if (xmlhttp.readyState==4)
             {// 4 = "loaded"
                if (xmlhttp.status==200)
                 {// 200 = "OK"
                    var txt= parseResponseText(xmlhttp.responseText)
                  var st = JSON.parse(txt);
            sf.USER_ID = st.BSM;
            sf.LOGIN_NAME = st.LOGIN_NAME;
            sf.NAME = st.NAME;
            sf.Pass = st.pass;
            sf.LERVER = st.LERVER;
            sf.XZQDM = st.XZQDM;
            sf.Role_Name = st.Role_Name;
            sf.RoleID = st.RoleID;
            sf.DEPT_ID = st.DEPT_ID;
            var arrUrl = window.location.href.split("/");
            if (arrUrl.length > 1) {
                if (sf.Pass == false && arrUrl[arrUrl.length - 1] != "index.html") {
                    if (window.parent != null && window.parent != undefined) {
                        window.parent.location.href = CLDJUrl + "/index.html";
                    }
                    else {
                        window.location.href = CLDJUrl + "/index.html";
                    }
                }
            }
            }
                }
        });
    };

    //登录页面，成功后进入一张图框架页
    this.Login = function (user, pwd) {
        var sf = this;
        var url = CLDJServiceUrl + "/SmwsFrame/Login";
        //var param = "{'uname':'" + user + "','password':'" + pwd + "'}";
        var param = "uname=" + user + "&password=" + pwd + "";
       
        GetSmJSON2(url, param, function () {
        	if (xmlhttp.readyState==4)
             {// 4 = "loaded"
                if (xmlhttp.status==200)
                 {// 200 = "OK"
                    var txt= parseResponseText(xmlhttp.responseText)
                  var st = JSON.parse(txt);
            
            sf.BSM = st.BSM;
            sf.LOGIN_NAME = st.LOGIN_NAME;
            sf.NAME = st.NAME;
            sf.Pass = st.pass;
            //sf.XZQDM = st.XZQDM;
            sf.LERVER = st.LERVER;
            sf.RoleID = st.RoleID;
            sf.RoleName = st.RoleName;
            sf.DEPT_ID = st.DEPT_ID;
            if (sf.Pass == true) {
                sf.Msg = "登录成功！";
                window.location.href = "frame.html";
            } else {
                sf.Msg = "密码不正确！";
            }
            }
  }
        });
    };
    //注销，返回到登录页
    this.LogOut = function () {
        var sf = this;
        var url = CLDJServiceUrl + "/SmwsFrame/LogOut";
        var param = "{user=" + sf.LOGIN_NAME + "}";
        GetSmJSON(url, param, function (txt) {
            sf.BSM = 0;
            sf.LOGIN_NAME = "";
            sf.NAME = "";
            sf.Pass = false;
            sf.XZQDM = "";
            sf.LERVER = "";
            sf.RoleID = "";
            sf.RoleName = "";
            sf.DEPT_ID = "";
            window.location.href = "index.html";
        });
    };


}

//服务器日期
function SmDate() {
    this.Value = undefined;
    this.GetServerDate = function () {
        var sf = this;
        var url = CLDJServiceUrl + "/SmwsFrame/GetCurrentDate";
        var param = "{}";
        GetSmJSON(url, param, function (txt) {
            sf.Value = txt;
        });
    }
};

//获取记录数
function GetSmRecordCount(sql) {
    var record = 0;
    var url = CLDJServiceUrl + "/SmwsFrame/GetSmRecordCount";
    var param = "{sql=" + sql + "}";
    GetSmJSON(url, param, function (txt) {
        record = txt;
    });
    return record;
}

function GetServerDate() {
    var smdate = new SmDate();
    smdate.GetServerDate();
    var result = smdate.Value.replace('/', '-');
    return smdate.Value;
}

/** 
 * 第一个参数指明要调用的方法， 
 * 第二个参数传递字符串 json 数据。 
 * 注意，虽然对于不管何种需求，都只是向服务器传递了一个 json字符串类型的数据 
 * 但由于 json 这个数据格式能够包含非常丰富的数据， 
 * 所以说，是完全能够弥补调用方法的参数仅限于一个的缺憾的~ 
 */  
function wrapData(strMethodName, strJsonParam) {  
    // 根据WSDL分析sayHelloWorld是方法名，parameters是传入参数名  
    var postData = "<?xml version=\"1.0\" encoding=\"utf-8\"?>";  
    postData += "<soap:Envelope ";  
    postData += "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" ";  
    postData += "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" ";  
    postData += "xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">";  
    postData += "<soap:Body><";  
    postData += strMethodName;  
    postData += " xmlns=\"http://localhost:8080/shareplantform/services\"><jsonData>";  
    postData += strJsonParam;  
    postData += "</jsonData></";  
    postData += strMethodName;  
    postData += "></soap:Body>";  
    postData += "</soap:Envelope>";  
    //alert("wrapData(strMethodName, strJsonParam)\n拼裝結果：\n" + postData);  
    return postData;  
}  
